home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Utils / GParted Live CD / Bin / gparted-livecd-0.2.2.iso / usr_sqfs / bin / guile-snarf < prev    next >
Encoding:
Text File  |  2005-07-27  |  2.8 KB  |  94 lines

  1. #!/bin/sh
  2. # Extract the initialization actions from source files.
  3. #
  4. #  Copyright (C) 1996, 97, 98, 99, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this software; see the file COPYING.  If not, write to
  18. # the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. # Boston, MA 02111-1307 USA
  20.  
  21. # Commentary:
  22.  
  23. # Usage: guile-snarf [-o OUTFILE] [CPP-ARGS ...]
  24.  
  25. # Initialization actions are extracted to OUTFILE or to standard
  26. # output when no OUTFILE has been specified or when OUTFILE is "-".
  27. # The C preprocessor is called with CPP-ARGS (which usually include a
  28. # input file) and the output is filtered for the actions.
  29. # If there are errors during processing, OUTFILE is deleted and the
  30. # program exits with non-zero status.
  31. # During snarfing, the pre-processor macro SCM_MAGIC_SNARFER is
  32. # defined.  You can use this to avoid including snarfer output files
  33. # that don't yet exist by writing code like this:
  34. #   #ifndef SCM_MAGIC_SNARFER
  35. #   #include "foo.x"
  36. #   #endif
  37. # If the environment variable CPP is set, use its value instead of the
  38. # C pre-processor determined at Guile configure-time: "i486-slackware-linux-gcc -E".
  39.  
  40. # Code:
  41.  
  42. ## funcs
  43.  
  44. modern_snarf ()                         # writes stdout
  45. {
  46.     ## Apparently, AIX's preprocessor is unhappy if you try to #include an
  47.     ## empty file.
  48.     echo "/* cpp arguments: $@ */" ;
  49.     ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true
  50.     grep "^ *\^ *\^" ${temp} | sed -e "s/^ *\^ *\^//"
  51. }
  52.  
  53. ## main
  54.  
  55. # process command line
  56. if [ x"$1" = x--help ] ; then
  57.     gawk '/^#.Commentary:/,/^#.Code:/' $0 | grep -v Code: \
  58.         | sed -e 1,2d -e 's/^. *//g'
  59.     exit 0
  60. fi
  61. if [ x"$1" = x-o ]
  62.     then outfile="$2" ; shift ; shift ;
  63.     else  outfile="-" ;
  64. fi
  65.  
  66. # set vars and handler -- handle CPP override
  67. cpp_ok_p=false
  68. tempdir="/tmp/snarf.$$"
  69. (umask 077 && mkdir $tempdir) || exit 1
  70. temp="$tempdir/tmp"
  71. if [ x"$CPP" = x ] ; then cpp="i486-slackware-linux-gcc -E" ; else cpp="$CPP" ; fi
  72.  
  73. trap "rm -rf $tempdir" 0 1 2 15
  74.  
  75. if [ ! "$outfile" = "-" ] ; then
  76.     modern_snarf "$@" > $outfile
  77. else
  78.     modern_snarf "$@"
  79. fi
  80.  
  81. # zonk outfile if errors occurred
  82. if $cpp_ok_p ; then
  83.     exit 0
  84. else
  85.     [ ! "$outfile" = "-" ] && rm -f $outfile
  86.     exit 1
  87. fi
  88.  
  89. # guile-snarf ends here
  90.